(旧Siv3D) 2 つの画像を横または縦に繋げて保存
https://gyazo.com/310f888c1ee8c60b96f1ca083a53c9e6
code: imgcomb.cpp
void Main()
{
Window::SetTitle(L"imgcomb");
Window::Resize(30 + 240 + 30 + 240 + 30, 500);
Graphics::SetBackground(Color(240));
Font font(10, Typeface::Bold);
GUIStyle guiStyle = GUIStyle::Default;
guiStyle.font = font;
GUI gui(guiStyle);
gui.setTitle(L"Save a combined image");
gui.setPos(30, 50 + 240 + 30);
WidgetStyle widgetStyle;
widgetStyle.font = font;
gui.add(GUIText::Create(L"image1", widgetStyle));
gui.add(L"tf-width1", GUITextField::Create(none, widgetStyle));
gui.add(GUIText::Create(L"x", widgetStyle));
gui.addln(L"tf-height1", GUITextField::Create(none, widgetStyle));
gui.add(GUIText::Create(L"image2", widgetStyle));
gui.add(L"tf-width2", GUITextField::Create(none, widgetStyle));
gui.add(GUIText::Create(L"x", widgetStyle));
gui.addln(L"tf-height2", GUITextField::Create(none, widgetStyle));
gui.add(L"bt-comb-h", GUIButton::Create(L"Holizontally", widgetStyle));
gui.add(L"bt-comb-v", GUIButton::Create(L"Vertically", widgetStyle));
Array<Image> image{ Image(240, 240, Palette::White), Image(240, 240, Palette::White) };
Array<Texture> texture{ Texture(image0), Texture(image1) }; const auto setGuiImageSizeText = &(const int w, const int h, const int imageSide /* 0 or 1 */) {
const Array<String> guiid_w{ L"tf-width1", L"tf-width2" };
const Array<String> guiid_h{ L"tf-height1", L"tf-height2" };
gui.textField(guiid_wimageSide).setText(Format(w)); gui.textField(guiid_himageSide).setText(Format(h)); };
const auto loadImage = &(const FilePath& filePath, const int imageSide /* 0 or 1 */) {
};
for (int i : step(image.size()))
{
setGuiImageSizeText(imagei.width, imagei.height, i); }
while (System::Update())
{
font(L"Drag & drop image files").drawCenter(Window::Size().x / 2, 40 / 2, Palette::Black);
Array<Rect> rect{ Rect(30, 50, 240), Rect(30 + 240 + 30, 50, 240) };
for (int i : step(rect.size()))
{
recti.drawShadow({ 5, 5 }, 14.0, 2.0, ColorF(0.0, 0.5)); recti.drawFrame(0.0, 3.0, Palette::Royalblue); Rect label(recti.pos, 16); label.draw(Palette::White).drawFrame(0.0, 3.0, Palette::Black);
font(Format(i + 1)).drawCenter(label.center, Palette::Royalblue);
}
if (Dragdrop::HasItems())
{
const auto items = Dragdrop::GetFilePaths();
const Point dropPos = Dragdrop::GetPos();
Array<int> imageSideNum{ 0, 1 };
if (rect1.contains(dropPos)) {
std::reverse(imageSideNum.begin(), imageSideNum.end());
}
for (int i = 0; i < Min((int)items.size(), 2); i++)
{
loadImage(itemsi, imageSideNumi); }
}
Optional<bool> holizontal = none;
if (gui.button(L"bt-comb-h").pushed)
{
holizontal = true;
}
else if (gui.button(L"bt-comb-v").pushed)
{
holizontal = false;
}
if (holizontal.has_value())
{
const auto save = Dialog::GetSaveImage();
if (save)
{
int w1 = Parse<int>(gui.textField(L"tf-width1").text);
int h1 = Parse<int>(gui.textField(L"tf-height1").text);
int w2 = Parse<int>(gui.textField(L"tf-width2").text);
int h2 = Parse<int>(gui.textField(L"tf-height2").text);
if (holizontal.value())
{
// Horizontally
if (h1 == h2)
{
Image newImage(w1 + w2, h1);
image0.scaled(w1, h1).overwrite(newImage, { 0, 0 }); image1.scaled(w2, h2).overwrite(newImage, { w1, 0 }); newImage.save(save.value());
}
}
else
{
// Vertically
if (w1 == w2)
{
Image newImage(w1, h1 + h2);
image0.scaled(w1, h1).overwrite(newImage, { 0, 0 }); image1.scaled(w2, h2).overwrite(newImage, { 0, h1 }); newImage.save(save.value());
}
}
}
}
}
}